#ifndef __INODE_H
#define __INODE_H
#include"global.h"
#include"list.h"
#include"ide.h"
#include"fs.h"

#define INODE_BLOCK_CNT 14
#define INODE_PER_SECTOR 8 
#define BLOCK_INDEX_CNT_PER_SECTOR SECTOR_SIZE/sizeof(uint32_t)
#define NODE_ALL_BLOCK_CNT (INODE_BLOCK_CNT-1+BLOCK_INDEX_CNT_PER_SECTOR)
//file max size about 70KB
#define FILE_SIZE_LIMIT NODE_ALL_BLOCK_CNT*BLOCK_SIZE
//keep pure inode size 64 
struct inode{
	uint32_t i_no;
	//file size
	uint32_t i_size;
	uint32_t blocks[INODE_BLOCK_CNT];
};

//inode wrap has other info only need in runtime
struct winode{
	struct inode pure_node;
	uint32_t open_cnt;
	bool write_flag;
	list_elem tag;
};

typedef enum{
	FS_BLOCK_BITMAP,
	FS_INODE_BITMAP
}bitmap_type;

struct winode* open_inode(struct partition*,uint32_t);
struct winode* create_inode(struct partition*,uint32_t);
void inode_sync(struct partition*,struct winode*,char*);
void close_inode(struct winode*);
bool release_inode(struct partition* part,int32_t i_no,char* iobuffer);
void fs_bitmap_sync(struct partition*,uint32_t,bitmap_type); 
int32_t fs_bitmap_alloc(struct partition* part,bitmap_type);
void node_all_block(struct partition*,struct inode*,uint32_t*,char*);
#endif
